﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hydra.Shell.Interfaces;
using Hydra.Shell.Enumerations;
using Hydra.PackageFramework.SurrogateTemps;
using Hydra.Shell.Implementations;
using System.Diagnostics;
using Hydra.Shell.Exceptions;
using Hydra.Shell;

namespace Hydra.PackageFramework
{
    public class ProjectNode : HierarchyNode
    {
        private Hydra.Shell.Interfaces.IServiceProvider site;
        private EventSinkCollection itemIdMap;
        private IHydraStatusBar statusBar;

        public EventSinkCollection ItemIdMap
        {
            get
            {
                if (itemIdMap == null)
                {
                    itemIdMap = new EventSinkCollection();
                }

                return itemIdMap;
            }
        }

        public Hydra.Shell.Interfaces.IServiceProvider Site
        {
            [DebuggerStepThrough()]
            set
            {
                site = value;
            }

            [DebuggerStepThrough()]
            get
            {
                if (site == null)
                {
                    throw new ObjectNotYetSitedException<ProjectNode>(this, "Site");
                }

                return site;
            }
        }

        public TrackDocumentsHelper Tracker
        {
            get
            {
                return this.tracker;
            }
        }

        public virtual int AddItemWithSpecific(uint itemIdLoc, HydraAddItemOperation op, string itemName, uint filesToOpen, string[] files, IntPtr dlgOwner, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, HydraAddResult[] result)
        {
            return 0;
        }

        public void OnOpenItem(string fullPath)
        {
            statusBar.Text = "Opening document '" + fullPath + "'...";
        }

        public bool IsClosed { get; set; }


        public bool GetSite(out Shell.Interfaces.IServiceProvider ppSP)
        {
            ppSP = site;
            return true;
        }

        public bool SetSite(Shell.Interfaces.IServiceProvider psp)
        {
            var serviceProvider = psp.GetService<IQueryServiceProvider>();
            ServiceLoadOperation<IHydraStatusBar> operation;

            if (serviceProvider.QueryService<IHydraStatusBar>(typeof(IHydraStatusBar).GetGuid(), out operation))
            {
                operation.ServiceLoaded += (sender, e) =>
                {
                    statusBar = (IHydraStatusBar) e.Service;
                };
            }

            site = psp;
            return true;
        }
        public bool GetNestedHierarchy(uint itemid, ref Guid iidHierarchyNested, out IntPtr ppHierarchyNested, out uint pitemidNested)
        {
            throw new NotImplementedException();
        }

        public bool GetGuidProperty(uint itemid, int propid, out Guid pguid)
        {
            throw new NotImplementedException();
        }

        public bool GetProperty(uint itemid, int propid, out object pvar)
        {
            throw new NotImplementedException();
        }

        public bool QueryClose(out int pfCanClose)
        {
            throw new NotImplementedException();
        }

        public bool SetGuidProperty(uint itemid, int propid, ref Guid rguid)
        {
            throw new NotImplementedException();
        }

        public bool SetProperty(uint itemid, int propid, object var)
        {
            throw new NotImplementedException();
        }

        public bool QueryEditProjectFile(bool p)
        {
            throw new NotImplementedException();
        }

        public string ReEvaluateProjectFileTargetName { get; set; }

        public void ResumeHydraBuild(string p)
        {
            throw new NotImplementedException();
        }

        public TrackDocumentsHelper tracker;

        public void SuspendHydraBuild()
        {
            throw new NotImplementedException();
        }

        public bool NodeHasDesigner(string p)
        {
            throw new NotImplementedException();
        }

        public int CompareNodes(HierarchyNode node, HierarchyNode n)
        {
            throw new NotImplementedException();
        }

        public void GenerateUniqueItemName(uint p, string p_2, string p_3, out string newFolderName)
        {
            throw new NotImplementedException();
        }

        public HierarchyNode CreateFolderNodes(string p)
        {
            throw new NotImplementedException();
        }

        public bool IsCurrentStateASuppressCommandsMode()
        {
            throw new NotImplementedException();
        }

        public virtual IList<HierarchyNode> GetSelectedNodes()
        {
            throw new NotImplementedException();
        }

        public bool CanProjectDeleteItems { get; set; }

        public override string Url
        {
            get { throw new NotImplementedException(); }
        }

        public override string Caption
        {
            get { throw new NotImplementedException(); }
        }

        public override Guid ItemTypeGuid
        {
            get { throw new NotImplementedException(); }
        }

        public object EventTriggeringFlag { get; set; }

        public HierarchyNode NodeFromItemId(uint itemid)
        {
            throw new NotImplementedException();
        }

        internal int ShowAllFiles()
        {
            throw new NotImplementedException();
        }

        internal int AddProjectReference()
        {
            throw new NotImplementedException();
        }

        internal int AddWebReference()
        {
            throw new NotImplementedException();
        }

        public override UIObjects.ILog Log
        {
            get { throw new NotImplementedException(); }
        }
    }
}
